import Vue from 'vue'

// loading 显示
Vue.prototype.uniShowLoading = function (title = '加载中', mask = true) {
  uni.showLoading({
    title,
    mask,
  })
}

// loading 隐藏
Vue.prototype.uniHideLoading = function () {
  uni.hideLoading()
}

// Toast 提示
Vue.prototype.uniShowToast = function (title = '', icon = 'none') {
  uni.showToast({
    title,
    icon,
  })
}

// 跳转到市民卡小程序
Vue.prototype.goCitizen = function (userId) {
  console.log('userId', userId)
  uni.navigateToMiniProgram({
    appId: 'wxc505ea1840da5ae6', // 替换为实际AppID
    path: '/pages/index/index', // 例如：'/pages/index/index?key=value'
    extraData: {
      // 需要传递给目标小程序的数据
      channelId: '02',
      channelApp: '05',
      merchantNo: '317000601001001',
      accessUserId: userId,
      redirectUrl: '/pages/home/index',
    },
    success(res) {
      console.log('跳转成功')
    },
    fail(err) {
      console.error('跳转失败', err)
    },
  })
}

Vue.prototype.isExternalLink = function (url) {
  return url?.startsWith('http://') || url?.startsWith('https://')
}
